const sampler_t sampler = CLK_ADDRESS_NONE | CLK_FILTER_NEAREST | CLK_NORMALIZED_COORDS_FALSE;

__kernel void ellpack_opencl_img(__global float * values, __global int * col_idx, __const int num_rows, __const int nonzeros_per_row,  __read_only image2d_t v, __global float * answer) {
  
	const int idx = get_global_id(0);
	
	if (idx >= num_rows)
		return;

	float sum = 0.0f;
	int _row = idx;
	
	for (int i = nonzeros_per_row * idx; i < (nonzeros_per_row * (idx + 1)); i++) {
		int _col = col_idx[i];
		float val = values[i];

		int coord = _col / 4;
		float4 temp = read_imagef(v, sampler, (int2)(0,coord));
		int imgPos = _col & 0x0003;
		float vecElement = 0;

		if (imgPos < 2) {
		if (imgPos == 0) vecElement = temp.x;
      else vecElement = temp.y;
	} else {
      if (imgPos == 2) vecElement = temp.z;
      else vecElement = temp.w;
	}
		sum += val * vecElement;
	}// for	
	answer[_row] = sum;	
}//kernel
